// src/utils/inputValidationMixin.js
export default {
    methods: {
        checkInputUsername(event) {
            const char = String.fromCharCode(event.which);
            // 允许输入字母、数字、下划线
            if (!/^[a-zA-Z0-9_]$/.test(char) && event.key !== 'Backspace' && event.key !== 'Delete') {
                event.preventDefault();
            }

            // 检查用户名长度是否在16个字符之下
            if (this.username.length >= 16 && event.key !== 'Backspace' && event.key !== 'Delete') {
                event.preventDefault();
            }
        },
        checkInputPassword(event) {
            const char = String.fromCharCode(event.which);
            // 允许输入字母、数字、下划线、小数点和@#*/
            if (!/^[a-zA-Z0-9_\.@#*\/\\]$/.test(char) && event.key !== 'Backspace' && event.key !== 'Delete') {
                event.preventDefault();
            }

            // 检查密码长度是否在32个字符之下
            if (this.password.length >= 32 && event.key !== 'Backspace' && event.key !== 'Delete') {
                event.preventDefault();
            }
        },
    },
};
